﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UIDesigner
{
    public partial class SetFormName : Form
    {
        public SetFormName()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox.Text.Length > 0)
            {
                DesignerName = this.textBox.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("名称不能为空", "错误", 
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        public string DesignerName
        {
            get;
            set;
        }

        private void textBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (this.textBox.Text.Length > 0)
                {
                    DesignerName = this.textBox.Text;
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }

        private void SetFormName_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(DesignerName))
            {
                this.textBox.Text = DesignerName;
            }
            this.button1.Focus();
        }
    }
}
